home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Turnbull China Bikeride
/
Turnbull China Bikeride - Disc 2.iso
/
STUTTGART
/
TEMP
/
GNU
/
bison
/
ActionFeat
< prev
next >
Wrap
Text File
|
1995-06-28
|
4KB
|
134 lines
Action Features
Previous: <Error Reporting=>ErrorRepor> * Next: <Algorithm=>Algorithm> * Up: <Interface=>Interface>
#Wrap on
{fH3}Special Features for Use in Actions{f}
Here is a table of Bison constructs, variables and macros that
are useful in actions.
#Indent +4
#Indent
{fEmphasis}$${f}
#Indent +4
Acts like a variable that contains the semantic value for the
grouping made by the current rule. \*Note <Actions=>Actions>.
#Indent
{fEmphasis}${fStrong}n{f}{f}
#Indent +4
Acts like a variable that contains the semantic value for the
{fStrong}n{f}th component of the current rule. \*Note <Actions=>Actions>.
#Indent
{fEmphasis}$<{fStrong}typealt{f}>${f}
#Indent +4
Like {fCode}$${f} but specifies alternative {fStrong}typealt{f} in the union
specified by the {fCode}%union{f} declaration. \*Note <Action Types=>ActionType>: Data Types of Values in Actions.
#Indent
{fEmphasis}$<{fStrong}typealt{f}>{fStrong}n{f}{f}
#Indent +4
Like {fCode}${fStrong}n{f}{f} but specifies alternative {fStrong}typealt{f} in the
union specified by the {fCode}%union{f} declaration.
\*Note <Action Types=>ActionType>: Data Types of Values in Actions.
#Indent
{fEmphasis}YYABORT;{f}
#Indent +4
Return immediately from {fCode}yyparse{f}, indicating failure.
\*Note <Parser Function=>ParserFunc>: The Parser Function {fCode}yyparse{f}.
#Indent
{fEmphasis}YYACCEPT;{f}
#Indent +4
Return immediately from {fCode}yyparse{f}, indicating success.
\*Note <Parser Function=>ParserFunc>: The Parser Function {fCode}yyparse{f}.
#Indent
{fEmphasis}YYBACKUP ({fStrong}token{f}, {fStrong}value{f});{f}
#Indent +4
Unshift a token. This macro is allowed only for rules that reduce
a single value, and only when there is no look-ahead token.
It installs a look-ahead token with token type {fStrong}token{f} and
semantic value {fStrong}value{f}; then it discards the value that was
going to be reduced by this rule.
If the macro is used when it is not valid, such as when there is
a look-ahead token already, then it reports a syntax error with
a message {fEmphasis}cannot back up{f} and performs ordinary error
recovery.
In either case, the rest of the action is not executed.
#Indent
{fEmphasis}YYEMPTY{f}
#Indent +4
Value stored in {fCode}yychar{f} when there is no look-ahead token.
#Indent
{fEmphasis}YYERROR;{f}
#Indent +4
Cause an immediate syntax error. This statement initiates error
recovery just as if the parser itself had detected an error; however, it
does not call {fCode}yyerror{f}, and does not print any message. If you
want to print an error message, call {fCode}yyerror{f} explicitly before
the {fEmphasis}YYERROR;{f} statement. \*Note <Error Recovery=>ErrorRecov>.
#Indent
{fEmphasis}YYRECOVERING{f}
#Indent +4
This macro stands for an expression that has the value 1 when the parser
is recovering from a syntax error, and 0 the rest of the time.
\*Note <Error Recovery=>ErrorRecov>.
#Indent
{fEmphasis}yychar{f}
#Indent +4
Variable containing the current look-ahead token. (In a pure parser,
this is actually a local variable within {fCode}yyparse{f}.) When there is
no look-ahead token, the value {fCode}YYEMPTY{f} is stored in the variable.
\*Note <Look-Ahead=>LookAhead>: Look-Ahead Tokens.
#Indent
{fEmphasis}yyclearin;{f}
#Indent +4
Discard the current look-ahead token. This is useful primarily in
error rules. \*Note <Error Recovery=>ErrorRecov>.
#Indent
{fEmphasis}yyerrok;{f}
#Indent +4
Resume generating error messages immediately for subsequent syntax
errors. This is useful primarily in error rules.
\*Note <Error Recovery=>ErrorRecov>.
#Indent
{fEmphasis}@{fStrong}n{f}{f}
#Indent +4
Acts like a structure variable containing information on the line
numbers and column numbers of the {fStrong}n{f}th component of the current
rule. The structure has four members, like this:
#Wrap off
#fCode
struct \{
int first\_line, last\_line;
int first\_column, last\_column;
\};
#f
#Wrap on
Thus, to get the starting line number of the third component, use
{fEmphasis}@3.first\_line{f}.
In order for the members of this structure to contain valid information,
you must make {fCode}yylex{f} supply this information about each token.
If you need only certain members, then {fCode}yylex{f} need only fill in
those members.
The use of this feature makes the parser noticeably slower.
#Indent